<?php

class Upload extends Public_Controller {

	function __construct()
	{
		parent::__construct();	
		$this->sSkinFile = 'ajax';
	}
	
	
	public function index($sAction = '')
	{
		if ($sAction !== '')
		{
			if (method_exists($this, $sAction) === true)
			{
				$this->$sAction();	
			}
		}
	}
	
	public function file_upload()
	{
		if (!empty($_FILES)) 
		{
			log_message('debug', '------------------------------------------------------------- $_FILES: '.print_r($_FILES, true));
			
			$tempFile = $_FILES['Filedata']['tmp_name'];
			$targetPath = $_SERVER['DOCUMENT_ROOT'] . $_POST['folder'] . '/';
			$targetFile =  str_replace('//','/',$targetPath).str_replace(' ', '_', $_FILES['Filedata']['name']);
			log_message('debug', '------------------------------------------------------------- tempFile: '.$tempFile);
			// Uncomment the following line if you want to make the directory if it doesn't exist
			// mkdir(str_replace('//','/',$targetPath), 0755, true);
			
			move_uploaded_file($tempFile,$targetFile);
			
			$sUploadType = $this->input->post('sUploadType', true, 'media');

			log_message('debug', '------------------------------------------------------------- sUploadType: '.$sUploadType);
			
			if ($sUploadType !== false)
			{
				$this->load->library($sUploadType.'_lib', '', 'upload_lib');
				
				
				$this->upload_lib->handle_upload($targetFile);
			}
		}
		
		$this->load->view('gen_output', array('output' => '1'));
		
		
	}
}

/* End of file welcome.php */
/* Location: ./system/application/controllers/welcome.php */

?>